package com.example.application2;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.security.KeyStore;
import java.util.Timer;
import java.util.TimerTask;

public class Activity3 extends AppCompatActivity {
    private  int cur=0;
    final int[] images = new int[]{
            R.drawable.a1,
            R.drawable.a2,
            R.drawable.a3,
            R.drawable.a4,
            R.drawable.a5
    };
    final int[] names= new int[]{
            R.id.imageView,
            R.id.imageView2,
            R.id.imageView3,
            R.id.imageView4,
            R.id.imageView5,
    };
    ImageView[] views=new ImageView[images.length];
     Handler handler =new Handler(){
        @Override
        public void handleMessage(Message msg){
            if(msg.what==0x123){
                for(int i=0;i<names.length;i++){
                    views[i].setImageResource(images[(i+cur)%names.length]);
                }
                cur++;
            }
            super.handleMessage(msg);
        }
    };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_3);
       for(int i=0;i<images.length;i++){
           views[i]=(ImageView) findViewById(names[i]);
       }
        new Timer().schedule(new TimerTask(){
            @Override
            public void run() {
                handler.sendEmptyMessage(0x123);
            }
        },0,2000);
        Button butt4 = (Button) findViewById(R.id.butt4);
        butt4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Activity3.this, MainActivity.class);
                startActivity(i);
            }
        });
    }
}

